{% extends '@PimUI/Form/pim-fields.html.twig' %}

{% block form_row_field %}
    <div class="InputBlock{% if attr.class is defined %} {{ attr.class }}{% endif %}">
        {{ form_label(form, '', { label_attr: label_attr|merge({ class: 'InputLabel' })}) }}
        <div class="InputContainer">
            {{- form_widget(form) -}}
        </div>
        {{- form_errors(form) -}}
    </div>
{% endblock %}

{%- block form_widget_simple -%}
    {%- set type = type|default('text') -%}
    {% set class = attr.class ?? '' %}
    {% if type == 'text' or type == 'password'  %}
        {% set class = 'InputText' %}
    {% endif %}
    {% if errors|length > 0  %}
        {% set class = class ~ ' ' ~ 'error' %}
    {% endif %}
    {% set attr = attr|merge({'class': class }) %}
    <input type="{{ type }}" {{ block('widget_attributes') }} {% if value == '\\' or value is not empty %}value="{{ value }}" {% endif %}/>
{%- endblock form_widget_simple -%}

{% block form_label %}
    {% apply spaceless %}
        {% if label is not same as(false) %}
            {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' AknFieldContainer-label')|trim}) %}
            {% if not compound %}
                {% set label_attr = label_attr|merge({'for': id}) %}
            {% endif %}
            {% if required %}
                {% set label_attr = label_attr|merge({'class': (label_attr.class ~ ' required')|trim}) %}
            {% endif %}
            {% if label is empty %}
                {% set label = name|humanize %}
            {% endif %}
            {% set isRadioLabel = form.parent.vars.expanded|default(false) and checked is defined %}
            {% set label = label|trans({}, translation_domain) %}
            {% if label_attr.truncate is defined and label_attr.truncate %}
                {% set label_attr = { 'title': label }|merge(label_attr) %}
                {% set label_attr = label_attr|merge({ 'class': (label_attr.class is defined ? label_attr.class ~ ' ' : '') ~ 'truncate' }) %}
            {% endif %}
            <label {% for attrname, attrvalue in label_attr | filter(attrname => attrname != 'truncate') %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
            {% if form.parent.vars.mode is defined and 'comparison' == form.parent.vars.mode %}
                <input type="checkbox" class="comparisonSelection exclude" />
            {% else %}
                {{ label }}{% if required and not isRadioLabel %} {{ 'required'|trans }}{% endif %}
            {% endif %}
            </label>
        {% endif %}
    {% endapply %}
{% endblock form_label %}

{%- block form_errors -%}
    {%- if errors|length > 0 -%}
        {%- for error in errors -%}
            <div class="Helper {% if form.parent %}Helper--inline{% endif %}">
                <span class="Icon"></span>
                <span class="Text">{{ error.message }}</span>
            </div>
        {%- endfor -%}
    {%- endif -%}
{%- endblock form_errors -%}
